function string.substringBefore(str,searchStr)
	if string.find(str,"&&") then
		str = string.replace(str,"&&","")
		searchStr = string.replace(searchStr,"&&","%%")
	end 
	
	local pos = string.find(str, searchStr)
	if not pos then
		return str
	end
	return string.sub(str,0,pos-1)
end
function string.substringAfter(str,searchStr)
	if string.find(str,"&&") then
		str = string.replace(str,"&&","")
		searchStr = string.replace(searchStr,"&&","%%")
	end 
	
	local pos = string.find(str, searchStr)
	if not pos then
		return str
	end
	return string.sub(str, pos + string.len(searchStr))
end	
function string.substringBetween (str,beginStr,endStr)
	local beginPos=string.find(str,beginStr)
	if beginPos ==nil then return false end
	if(beginPos<=0) then
		return false;
		end
	local beginStrLen = string.len(beginStr)
	strlen=string.len(str)
	local leftstr=string.sub(str,beginPos+beginStrLen,strlen)
	local endPos=string.find(leftstr,endStr)
	if(endPos<=0) then
	return false;
	end
	return string.sub(leftstr,1,endPos-1)
end
function string.substringBetweenArray (str,beginStr,endStr)	
	local resultArr={};
	while true do
		local beginPos=string.find(str,beginStr,1,1)
		if beginPos ==nil then break end
		if(beginPos<=0) then
			break;
		end
		local beginStrLen = string.len(beginStr)
		local strlen=string.len(str)
		local leftstr=string.sub(str,beginPos+beginStrLen,strlen)
		local endPos=string.find(leftstr,endStr,1,1)
		if(endPos<=0) then
			break;
		end
		local ret = string.sub(str,beginPos+beginStrLen,beginPos+endPos-1)
		table.insert(resultArr, ret);
		str = string.sub(str,beginPos+endPos);
	end		
	return resultArr;	
end

function string.substring(str,pos)
	return string.sub(str, pos, pos)
end

function string.replace(str,searchStr,replaceStr)
	return string.gsub(str,searchStr,replaceStr)
end

--[[判断str是否以substr结尾。是返回true，否返回false，失败返回失败信息]]
function string.endsWith ( str, substr)
	if str == nil or substr == nil then
		return nil, "the string or the sub-string parameter is nil"
	end
	str_tmp = string.reverse(str)
	substr_tmp = string.reverse(substr)
	if string.find(str_tmp, substr_tmp) ~= 1 then
		return false
	else
		return true
	end
end

function string.insert ( str, substr)
	local s = "";
	for i = 1,string.len(str) ,3 do
		if i + 3 >= string.len(str) then
			s = s .. string.sub(str,i, i* 3)
		else
			s = s .. string.sub(str,i, i* 3).. substr
		end
	end
	return s
end

function string.contains(str,searchStr)
	if str==nil or string.find(str,searchStr)==nil then
		return false
	else
		return true
	end
end
--获取字符个数
function string.getStringCount(str)
	local m,n=str:gsub('[\128-\255]','')
	return string.len(m)+tonumber(n)/3
end
--获取字节数
function string.getBytesCount(str)
	local m,n=str:gsub('[\128-\255]','')
	return string.len(m)+number_val(n) 
end
--获取中文个数
function string.getWordCount(str)
	local m,n=str:gsub('[\128-\255]','')
	return string.len(m)/2+number_val(n)/3
end
--获取字数(任意字符都代表1)
function string.utf8len(str)  
    local len  = string.len(str)  
    local left = len  
    local cnt  = 0  
    local arr  = {0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc}  
    while left ~= 0 do  
        local tmp = string.byte(str, -left)  
        local i   = #arr  
        while arr[i] do  
            if tmp >= arr[i] then  
                left = left - i  
                break  
            end  
            i = i - 1  
        end  
        cnt = cnt + 1  
    end  
    return cnt  
end 

function string.trim(input)
    input = string.gsub(input, "^[ \t\n\r]+", "")
    return string.gsub(input, "[ \t\n\r]+$", "")
end

function string.trimSpace(str)
    return string.gsub(str, " ", "")
end

function string.reverse(s)
    local r = ""
    for i = #s, 1, -1 do
        r = r .. string.sub(s, i, i)
    end
    return r
end

function string.starts_with(str, start)
	return str:sub(1, #start) == start
end

function string.ends_with(str, ending)
	return ending == "" or str:sub(-#ending) == ending
end

--c# string.Format
function string.Format(str, ...)
	return System.String.Format(str, ...)
end

function string.findLastIndex(str, char)
	local first, last = string.find(str, string.format("%s[^%s]*$", char, char))
	return first
end